package cn.xfdzx.android.apps.shop.adapter;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.AfterServiceInfoActivity;
import cn.xfdzx.android.apps.shop.activity.AfterServiceInfoMarketActivity;
import cn.xfdzx.android.apps.shop.activity.ShopActivity;
import cn.xfdzx.android.apps.shop.bean.AfterSalesListMarketBean;
import cn.xfdzx.android.apps.shop.bean.AfterSalesListRetailBean;

/**
 * Creator: zf.
 * Date: 2020/9/24.
 * Description:批发-售后列表适配器.
 */
public class AfterSalesListMarketAdapter extends BaseQuickAdapter<AfterSalesListMarketBean.DataBean, BaseViewHolder>  {
    private OnItemOnClickListener onItemOnClickListener;
    private List<AfterSalesListMarketBean.DataBean> marketAfterListdata;//列表
    private AfterSalesListMarket_InnergoodsAdapter adapter;
    public AfterSalesListMarketAdapter(@Nullable List<AfterSalesListMarketBean.DataBean> data) {
        super(R.layout.item_order_dai_pay2, data);
        this.marketAfterListdata = data;
    }

    @Override
    public void setData(int index, @NonNull AfterSalesListMarketBean.DataBean data) {
        super.setData(index, data);
    }


    @Override
    protected void convert(final BaseViewHolder viewHolder, final AfterSalesListMarketBean.DataBean date) {
        View viewGotoShop = viewHolder.getView(R.id.view_goto_shop);
        TextView tv_lianxi_kefu = viewHolder.getView(R.id.tv_lianxi_kefu);
        TextView tv_lookprocess = viewHolder.getView(R.id.tv_lookprocess);
        tv_lookprocess.setVisibility(View.VISIBLE);

        TextView tv_state = viewHolder.getView(R.id.tv_state);
        RecyclerView rvOrderGoods = viewHolder.getView(R.id.rv_order_goods);

        switch (String.valueOf(date.getApply().getStatus())){
            case "1":
            case "2":
            case "5":
                tv_state.setText("退款处理中");
            break;
            case "3":
                tv_state.setText("退款被驳回");
                break;
            case "4":
                tv_state.setText("退款已取消");
                break;
            case "6":
                tv_state.setText("退款成功");
                break;
        }

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvOrderGoods.setLayoutManager(linearLayoutManager);
        adapter = new AfterSalesListMarket_InnergoodsAdapter(date.getGoods());
        rvOrderGoods.setAdapter(adapter);

        viewHolder.setText(R.id.tv_shop_name,date.getStore().getStore_name()+"")
        .setText(R.id.tv_goodsnum,"共" + date.getApply().getApply_num() + "件")
        .setText(R.id.tv_payprice,"¥" +date.getApply().getApply_price());
//
//        ImageGlideUtil.loadImage(mContext,imageView,date.getProductInfo().getImage());
        tv_lianxi_kefu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callPhone("15810103429");
            }
        });

        tv_lookprocess.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, AfterServiceInfoMarketActivity.class);
                intent.putExtra("orderId", date.getApply().getOrder_id());
                intent.putExtra("applyId", date.getApply().getId()+"");
                mContext.startActivity(intent);
            }
        });

       viewGotoShop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(mContext, ShopActivity.class);
//                intent.putExtra("shop_id",date.getStore().getId()+"");
//                mContext.startActivity(intent);
            }
        });
    }
    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<AfterSalesListMarketBean.DataBean> list){
        this.marketAfterListdata = list;
        super.replaceData(list);
    }

    public void setItemAddMoveListener(OnItemOnClickListener listener){
        this.onItemOnClickListener = listener;
    }

    public interface OnItemOnClickListener {
        void onItemAddMoveClick(int position, int count, AfterSalesListMarketBean.DataBean date);
    }

    /**
     * 拨打电话（跳转到拨号界面，用户手动点击拨打）
     *
     * @param phoneNum 电话号码
     */
    public void callPhone(String phoneNum) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + phoneNum);
        intent.setData(data);
        mContext.startActivity(intent);
    }
}
